<?
if (isset($_POST['ID']))
{
    if ($_POST['ID'] != $user->getID() && !$user->isAdmin())
    {
        $error[] = 'You are not an administrator so you cannot change somebody elses user account.';
    }
    else
    {
        $user->updateUser($_POST['ID'], $_POST);
        $note[] = 'User account updated.';
        
        if ($_POST['password1'] != '')
        {
            if ($_POST['password1'] != $_POST['password2'])
            {
                $error[] = 'New passwords do not match! Not Changed.';
            }
            elseif (strlen($_POST['password1']) < 6)
            {
                $error[] = 'New password is too short.  At least 6 characters required.';
            }
            else
            {
                $user->updatePassword($_POST['ID'], $_POST['password1']);
                $note[] = 'User password updated.';
            }
        }
    }
}

$ID = $user->getID();
if (isset($_GET['ID']))
{
    $ID = $_GET['ID'];
}

if (!$user->isAdmin() && $ID != $user->getID())
{
    $ID = $user->getID();
}

$account = $user->getUser($ID);

$smarty->assign('account_username', $account['username']);
$smarty->assign('account_firstname', $account['firstname']);
$smarty->assign('account_lastname', $account['lastname']);
$smarty->assign('account_email', $account['email']);
$smarty->assign('account_lastlogin', $account['lastlogin']);
$smarty->assign('account_ID', $account['ID']);
$smarty->assign('account_code', $account['code']);

if ($ID == $user->getID() || $user->isAdmin())
{
    $smarty->assign('input', true);
}

?>
